package com.piggy.logi.sys.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.vo.LogiScheduleLogVo;
import com.piggy.logi.sys.bo.LogiScheduleLogQueryBo;
import com.piggy.logi.sys.bo.LogiScheduleLogEditBo;
import com.piggy.logi.sys.service.ILogiScheduleLogService;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.piggy.common.core.domain.R;

import java.lang.Integer;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * 调度车次日志Controller
 *
 * @author piggy
 * @date 2023-12-07
 */
@Api(value = "调度车次日志控制器", tags = {"调度车次日志管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/schedulelog")
public class LogiScheduleLogController extends BaseController {

    private final ILogiScheduleLogService iLogiScheduleLogService;

    /**
     * 查询调度车次日志列表
     */
    @ApiOperation("查询调度车次日志列表")
    //@SaCheckPermission("sys:schedulelog:list")
    @PostMapping("/list")
    public TableDataInfo<LogiScheduleLogVo> list(@Validated @RequestBody LogiScheduleLogQueryBo bo) {
        return iLogiScheduleLogService.queryPageList(bo);
    }

    /**
     * 导出调度车次日志列表
     */
    @ApiOperation("导出调度车次日志列表")
    //@SaCheckPermission("sys:schedulelog:export")
    @Log(title = "调度车次日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiScheduleLogQueryBo bo, HttpServletResponse response) throws IOException {
        List<LogiScheduleLogVo> list = iLogiScheduleLogService.queryList(bo);
        ExcelUtil<LogiScheduleLogVo> util = new ExcelUtil<LogiScheduleLogVo>(LogiScheduleLogVo.class);
        util.exportExcel(response, list, "调度车次日志");
    }

    /**
     * 获取调度车次日志详细信息
     */
    @ApiOperation("获取调度车次日志详细信息")
    //@SaCheckPermission("sys:schedulelog:query")
    @GetMapping("/{id}")
    public R<LogiScheduleLogVo> getInfo(@NotNull(message = "主键不能为空")
                                        @PathVariable("id") Long id) {
        return R.ok(iLogiScheduleLogService.queryById(id));
    }

    /**
     * 新增调度车次日志
     */
    @ApiOperation("新增调度车次日志")
    //@SaCheckPermission("sys:schedulelog:add")
    @Log(title = "调度车次日志", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiScheduleLogVo> add(@Validated @RequestBody LogiScheduleLogEditBo bo) {
        return R.ok(iLogiScheduleLogService.insertByAddBo(bo));
    }

    /**
     * 修改调度车次日志
     */
    @ApiOperation("修改调度车次日志")
    //@SaCheckPermission("sys:schedulelog:edit")
    @Log(title = "调度车次日志", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiScheduleLogVo> edit(@Validated @RequestBody LogiScheduleLogEditBo bo) {
        return R.ok(iLogiScheduleLogService.updateByEditBo(bo));
    }

    /**
     * 删除调度车次日志
     */
    @ApiOperation("删除调度车次日志")
    //@SaCheckPermission("sys:schedulelog:remove")
    @Log(title = "调度车次日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                             @PathVariable Long[] ids) {
        return R.ok(iLogiScheduleLogService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
